# Contributor: messense <messense@icloud.com>
# Maintainer: messense <messense@icloud.com>
pkgname=py-spy
pkgver=0.3.11
pkgrel=0
pkgdesc="Sampling profiler for Python programs"
url="https://github.com/benfred/py-spy"
arch="aarch64 armv7 armhf x86_64 ppc64le" # limited by rust
license="MIT"
makedepends="cargo zlib-dev libunwind-dev xz-dev"
checkdepends="python3 bash"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/benfred/py-spy/archive/v$pkgver.tar.gz"

build() {
	cargo build --release --locked

	./target/release/py-spy completions bash > $pkgname.bash
	./target/release/py-spy completions fish > $pkgname.fish
	./target/release/py-spy completions zsh > $pkgname.zsh
}

check() {
	# enable interpreter "python" hack
	mkdir "$builddir"/pythonbindir
	ln -s /usr/bin/python3 "$builddir"/pythonbindir/python
	export PATH="$PATH:$builddir/pythonbindir"

	# Some tests need additional privileges
	cargo test --release --locked -- \
		--skip test_busy_loop \
		--skip test_delayed_subprocess \
		--skip test_local_vars \
		--skip test_long_sleep \
		--skip test_negative_linenumber_increment \
		--skip test_recursive \
		--skip test_subprocesses \
		--skip test_subprocesses_zombiechild \
		--skip test_thread_names \
		--skip test_thread_reuse \
		--skip test_unicode
}

package() {
	install -Dm0755 target/release/$pkgname -t "$pkgdir"/usr/bin
	install -Dm0644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/completions/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="ff6a9cf84da7e821b9245868597fc813217f3c1a4637f70e3d70425a61b466033463609ce48795f4983c50519f6a20470641d3b64fee916e4732d4e12ec99fd7  py-spy-0.3.11.tar.gz"
